// File:   roll_dice2/RollDicePanel.java
// Description: Panel of GUI, shows button and two dice.
// Author: Fred Swartz
// Date:   2005-01-29

package rolldice;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

///////////////////////////////////////////////////////// class RollDicePanel
/** RollDicePanel.java - Panel builds GUI for RollDice application/applet.
    It subclasses JPanel to contain two dice and a button to roll them.

    @author Fred Swartz
    @version 2005-01-29
*/
public class RollDicePanel extends JPanel {
    //=============================================== instance variables
    private Die Die1;     // component for one die 
    private Die Die2;
    private Die Die3;
    private Die Die4;
    private Die Die5;
    private Die Die6;

    //====================================================== constructor
    /** Create border layout panel with one button and two dice. */
    RollDicePanel() {
        //... Create the dice
        Die1 = new Die();
        Die2 = new Die();
        Die3 = new Die();
        Die4 = new Die();
        Die5 = new Die();
        Die6 = new Die();
        
        //...Create the button to roll the dice
        JButton rollButton = new JButton("New Roll");
        rollButton.setFont(new Font("Sansserif", Font.PLAIN, 24));
        
        //... Add listener.
        rollButton.addActionListener(new RollListener());
        
        //... Layout components
        this.setLayout(new FlowLayout());
        this.add(rollButton);
        this.add(Die1);
        this.add(Die2);
        this.add(Die3);
        this.add(Die4);
        this.add(Die5);
        this.add(Die6);
    }//end constructor
    
    
    /////////////////////////////////// inner listener class RollListener
    /** Inner listener class for Roll button. */
    private class RollListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            Die1.roll();
            Die2.roll();
            Die3.roll();
            Die4.roll();
            Die5.roll();
            Die6.roll();
        }
    }
}
